feat(autonatv2): expose AllowPrivateAddrs via an Option#3513
Conversation
| // autoNATSettings is used to configure AutoNAT | ||
| type autoNATSettings struct { | ||
| allowPrivateAddrs bool | ||
| AllowPrivateAddrs bool |
There was a problem hiding this comment.
Why does this field (and other similar fields across this diff) need to be public?
There was a problem hiding this comment.
On nim-libp2p we have an integration test between nim-libp2p and go-libp2p for autonat, since that is not yet present in https://github.com/libp2p/unified-testing. For that we need to allow private addresses on go-libp2p (just like you do in your tests), but there's no way to do that as a user currently. What we've been doing is cloning go-libp2p and applying an ugly patch instead. This makes the option public so we no longer have to do that there.
There was a problem hiding this comment.
But why do you need the field of the autoNATSettings struct to be public? Remember in Go, when you capitalize a field you make it public to users outside the package it is defined in.
There was a problem hiding this comment.
We have two scripts that instanciate peers: one in go that imports go-libp2p and another one in nim that imports nim-libp2p, they instanciate autonat-capable peers and communicate. For that test, the go script (a "user outside the package", if you will) needs to be able to set autonat settings, specifically the one that allows private ip addresses.
Summary
Expose AutoNATv2's
allowPrivateAddrssetting through the top-levellibp2ppackage so callers can opt in without patching the library.
Changes
p2p/protocol/autonatv2allowPrivateAddrsfield/option to the exportedAllowPrivateAddrs(commite3a1d72d).config,options.goConfig.AutoNATv2AllowPrivateAddrs.libp2p.AutoNATv2AllowPrivateAddrs()option.EnableAutoNATv2(), the fx provider passesautonatv2.AllowPrivateAddrstoautonatv2.New(commit
b85ffade).libp2p_test.goAdd a smoke test verifying that:
successfully builds a host.
Motivation
nim-libp2p's AutoNATv2 interop tests currently maintain a patch againstgo-libp2pto disable private-address filtering:disable-filtering-of-private-ip-addresses.patch(
interop/autonatv2/go-peer/...)The setting already exists internally; this change simply exposes it through the
public API so the patch can be removed (see
nim-libp2p#1699).Notes
production use.
false.